package wn.tcpip.socket.netty.business;

import com.alibaba.fastjson.JSON;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import wn.tcpip.socket.netty.business.factory.ResoverAbs;
import wn.tcpip.socket.netty.cache.NettyChannelMap;
import wn.tcpip.socket.netty.jdbc.NettyJdbcTool;
import wn.tcpip.socket.netty.model.GPSBackRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;
import wn.tcpip.socket.netty.model.GpsEquipmentPositionEntity;
import wn.tcpip.socket.netty.model.GpsStateEntity;
import wn.tcpip.socket.spring.SpringUtil;
import wn.tcpip.socket.util.ProtocolUtil;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * Created by zhangqin on 2017/4/19.
 */
@Service
public class LoginResoverImp extends ResoverAbs{
    private static  final Logger logger = LoggerFactory.getLogger(LoginResoverImp.class);
    @Resource
    private NettyJdbcTool nettyJdbcTool;
    @Override
    public String getResponse(GPSBackRequest request) {
        String im = request.getContent().substring(1);
        if(nettyJdbcTool.hasImei(im)){
            NettyChannelMap.add( im,request.getChannel());
                logger.info("sb：{}=====loginSuccess", im);
        }else{
            logger.info("sb：{}=====loginError", im);
            request.getChannel().disconnect();
            return null;//不返回信息 设备会认为没有登录成功
        }

        return super.makeDefaultResponse(request);
    }

}
